package com.zch.jh.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.Set;

/**
 * A ItemType.
 */
@Entity
@Table(name = "item_type")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class ItemType implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "type_name")
    private String typeName;

    @Column(name = "offset", precision = 21, scale = 2)
    private BigDecimal offset;

    @Column(name = "des")
    private String des;

    @Column(name = "memo")
    private String memo;

    @ManyToMany(mappedBy = "itemTypes")
    @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
    @JsonIgnore
    private Set<Item> items = new HashSet<>();

    // jhipster-needle-entity-add-field - JHipster will add fields here
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTypeName() {
        return typeName;
    }

    public ItemType typeName(String typeName) {
        this.typeName = typeName;
        return this;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public BigDecimal getOffset() {
        return offset;
    }

    public ItemType offset(BigDecimal offset) {
        this.offset = offset;
        return this;
    }

    public void setOffset(BigDecimal offset) {
        this.offset = offset;
    }

    public String getDes() {
        return des;
    }

    public ItemType des(String des) {
        this.des = des;
        return this;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public String getMemo() {
        return memo;
    }

    public ItemType memo(String memo) {
        this.memo = memo;
        return this;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public Set<Item> getItems() {
        return items;
    }

    public ItemType items(Set<Item> items) {
        this.items = items;
        return this;
    }

    public ItemType addItem(Item item) {
        this.items.add(item);
        item.getItemTypes().add(this);
        return this;
    }

    public ItemType removeItem(Item item) {
        this.items.remove(item);
        item.getItemTypes().remove(this);
        return this;
    }

    public void setItems(Set<Item> items) {
        this.items = items;
    }
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof ItemType)) {
            return false;
        }
        return id != null && id.equals(((ItemType) o).id);
    }

    @Override
    public int hashCode() {
        return 31;
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "ItemType{" +
            "id=" + getId() +
            ", typeName='" + getTypeName() + "'" +
            ", offset=" + getOffset() +
            ", des='" + getDes() + "'" +
            ", memo='" + getMemo() + "'" +
            "}";
    }
}
